﻿#region License

// This file is part of Grawlix.
// 
// Grawlix is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as
// published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
// Grawlix is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public
// License along with Grawlix.  If not, see
// <http://www.gnu.org/licenses/>.

#endregion

using System;
using System.Drawing;
using Grawlix.Application;
using Grawlix.Geometry;
using Grawlix.Services;
using Grawlix.Services.Rendering;

namespace Grawlix.Test.Default
{
	/// <summary>
	/// The main <see cref="UIGovernor"/> for the assembly.
	/// </summary>
	public class MainGovernor : UIGovernor
	{
		/// <summary>
		/// The texture resource.
		/// </summary>
		private readonly ITextureResource _texture;

		/// <summary>
		/// Initializes a new instance of the 
		/// <see cref="MainGovernor"/> class.
		/// </summary>
		/// <param name="gameKernel">The game kernel to acquire
		/// services from.</param>
		/// <exception cref="ArgumentNullException"><c>gameKernel</c>is
		/// null.</exception>
		public MainGovernor(IGameKernel gameKernel)
			: base(gameKernel)
		{
			_texture =
				TextureFactory.Resolve(
					new Uri("game:///WikimediaGrawlix"));
		}

		/// <summary>
		/// Renders to the specified device.
		/// </summary>
		/// <param name="device">The device to render to.</param>
		/// <param name="camera">The area to render within.</param>
		public override void Render(IRenderDevice device,
		                            Rect camera)
		{
			base.Render(device, camera);
			device.DrawRectangle(Color.Blue, new Rect(4, 4, 200, 200));
			if (_texture.Ready)
			{
				device.DrawTexture(_texture.State,
				                   new Rect(0, 0, 300, 600), Color.Wheat,
				                   new Rect(100, 100, 400, 700));
			}
			device.DrawRectangle(Color.Red, new Rect(8, 8, 200, 200));
		}
	}
}